//
//  ViewController2.m
//  nmrsc
//
//  Created by xumckay on 16/1/9.
//  Copyright © 2016年 bric. All rights reserved.
//

#import "ClassifyViewController.h"
#import "ProductClassifyCell.h"
#import "DetailProductClassifyController.h"
@interface ClassifyViewController ()

@property (strong,nonatomic)UISegmentedControl *segementView;
@property (strong,nonatomic)NSArray *dataArray; //两个按钮覆盖数据源，然后刷新
@property (strong,nonatomic)UITableView *tableView;
@end

@implementation ClassifyViewController

- (void)viewDidLoad {
    [super viewDidLoad];
   
    self.view.backgroundColor=[UIColor whiteColor];
    _segementView=[[UISegmentedControl alloc]initWithItems:@[@"商品分类",@"特色县产"]];
    _segementView.frame=CGRectMake(30,10,kDeviceWidth-60,30);
    _segementView.segmentedControlStyle=UISegmentedControlStyleBar;
    _segementView.tintColor=COLOR(36, 148, 88, 1);
    _segementView.selectedSegmentIndex=0;
    [_segementView addTarget:self action:@selector(segementViewClicked:) forControlEvents:UIControlEventValueChanged];
    [self.view addSubview:_segementView];
    
    UIView *sep=[[UIView alloc]initWithFrame:CGRectMake(0,49.5,kDeviceWidth,0.5)];
    sep.backgroundColor=COLOR(200, 200, 200, 1);
    [self.view addSubview:sep];
    
    _dataArray=[[NSArray alloc]init];
    _tableView=[[UITableView alloc]initWithFrame:CGRectMake(0,50,kDeviceWidth,kDeviceHeight-64-49-50)];
    _tableView.delegate=self;
    _tableView.dataSource=self;
    _tableView.separatorStyle=UITableViewCellSeparatorStyleNone;

//    _tableView.header=[MJRefreshNormalHeader headerWithRefreshingBlock:^{
//
//        [self getAllAreaProductClassify];
//        
//    }];
    
    [self.view addSubview:_tableView];
    _dataArray=@[@"1"];
}

-(void)segementViewClicked:(UISegmentedControl*)seg
{
    NSInteger index=seg.selectedSegmentIndex;
    switch (index) {
        case 0: //商品分类
        {
            _dataArray=@[@"1"];
            [_tableView reloadData];
        }
            break;
            
        case 1: //特色县产
        {

            _dataArray=@[@"1",@"2",@"2",@"2",@"2",@"2",@"2",@"2",@"2",@"2"];
            [_tableView reloadData];
        }
            break;
        default:
            break;
    }
}

//获得地区商品分类列表数据
-(void)getAllAreaProductClassify
{
    HLManager *hl=[HLManager sharedManager];
    AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
    manager.responseSerializer = [AFHTTPResponseSerializer serializer];
    manager.requestSerializer.timeoutInterval = kTimeoutInterval;
    manager.securityPolicy = [hl getHttpsSetting];
    
    // 填写表单
    NSMutableDictionary *dict = [[NSMutableDictionary alloc] init];
    
    NSString *urlStr = [NSString stringWithFormat:@"%@/front/home/getTopNavList.do",kServerNetwork];
    
    [manager POST:urlStr parameters:dict constructingBodyWithBlock:^(id<AFMultipartFormData> formData) {
        
    } success:^(AFHTTPRequestOperation *operation, id responseObject) {
        
        NSLog(@"responseObject = %@",responseObject);
        NSError *error = nil;
        NSDictionary *dict = [NSJSONSerialization JSONObjectWithData:responseObject options:0 error:&error];
        NSLog(@"dict++--,,%@",dict);
        
        if ([[dict objectForKey:@"status"] intValue] == 1) {


        
        }
    }
    failure:^(AFHTTPRequestOperation *operation, NSError *error)
    {
              NSLog(@"error = %@",error.description);
    }];
    
}

//获取产品种类的列表数据
-(void)getAllKindOfProduct
{
    
    
}

#pragma mark   ---UITableViewDelegate

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return _dataArray.count;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *identifier1=@"cell1";
    static NSString *identifier2=@"cell2";

    ProductClassifyCell *cell=[tableView dequeueReusableCellWithIdentifier:identifier1];
    if (!cell) {
        cell=[[ProductClassifyCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier1];
        cell.selectionStyle=UITableViewCellSelectionStyleNone;
    }
    return cell;
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    DetailProductClassifyController *detailVC=[[DetailProductClassifyController alloc]init];
    [self.navigationController pushViewController:detailVC animated:YES];
    
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 70;
}


@end
